/*
 * @Author: your name
 * @Date: 2022-04-11 21:00:48
 * @LastEditTime: 2022-04-24 00:09:33
 * @LastEditors: Please set LastEditors
 * @Description: 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 * @FilePath: \type-h5\src\api\index-tab.ts
 */
import {
  IResult,
  IPartner,
  IOutNumber,
  ISchedule,
  IListing,
  IRecordList,
  IRecordRes,
  IListingConfirm,
} from "../interfaces";
import { instance } from "../utils";

/** 获取数据概览 */
export const fetchOutNumber = (
  spaceId: string
): Promise<IResult<IOutNumber>> => {
  return instance.get(`/space/${spaceId}/outNumber`).then(({ data }) => data);
};
/** 获取事项进度 */
export const fetchSchedule = (
  spaceId: string
): Promise<IResult<ISchedule[]>> => {
  return instance.get(`/space/${spaceId}/getSchedule`).then(({ data }) => data);
};

/** 获取确认项 */
export const fetchListing = (spaceId: string): Promise<IResult<IListing[]>> => {
  return instance.get(`/space/${spaceId}/listing`).then(({ data }) => data);
};

/** 获取确认项详情 */
export const fetchListingDetail = (
  spaceId: string,
  listingId: string,
  accessKey: string
): Promise<IResult<IListing>> => {
  if (!accessKey || accessKey === "undefined") {
    return instance
      .get(`/space/${spaceId}/listing/${listingId}`)
      .then(({ data }) => data);
  }
  return instance
    .get(`/space/${spaceId}/listing/${listingId}?accessKey=${accessKey}`)
    .then(({ data }) => data);
};

/** 获取确认项列表 */
export const fetchListingList = (
  spaceId: string,
  listingId: string,
  accessKey: string
): Promise<IResult<IListingConfirm[]>> => {
  if (!accessKey || accessKey === "undefined") {
    return instance
      .get(`/space/${spaceId}/listing/${listingId}/confirm`)
      .then(({ data }) => data);
  }
  return instance
    .get(
      `/space/${spaceId}/listing/${listingId}/confirm?accessKey=${accessKey}`
    )
    .then(({ data }) => data);
};

/** 获取交付状态 */
export const fetchRecordList = (
  spaceId: string,
  body: { current: number; pageSize: number }
): Promise<IResult<IRecordRes>> => {
  return instance
    .post(`/space/${spaceId}/deliveryRecord/list`, body)
    .then(({ data }) => data);
};
